package com.zbkj.service.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

import java.util.Locale;

/**
 * 国际化工具类*/
@Component
public class LocalUtil {

    @Autowired
    public MessageSource messageSource;



    /**
     * 获取单个国际化翻译值
     */
    public String get(String msgKey)
    {
        try
        {
            Locale locale = LocaleContextHolder.getLocale();
            String message = messageSource.getMessage(msgKey, null, locale);
            return message;
        }
        catch (Exception e)
        {
            return msgKey;
        }
    }
}
